using System;
using System.Collections.Generic;
using System.Text;

namespace Kenly.DBFramework.Gateway
{
    /// <summary>
    /// Creates instances.
    /// </summary>
    public static class ObjectBuilder
    {
        /// <summary>
        ///  Creates a list of instances.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="count"></param>
        /// <returns></returns>
        public static List<T> CreateInstances<T>(int count)
        {
            List<T> items = new  List<T>();
            for (int i = 0; i < count; i++)
            {
               items.Add(CreateInstance<T>());
            }
            return items;
        }

        /// <summary>
        ///  Creates a instance.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T CreateInstance<T>()
        {
            T item;
            item=System.Activator.CreateInstance<T>();
            return item;
        }

        /// <summary>
        ///  Creates a list of instances.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static object[] CreateInstances(Type type,int count)
        {
            object[] items = new object[count];
            for (int i = 0; i < items.Length; i++)
            {
                items[i] = CreateInstance(type);
            }
            return items;
        }

        /// <summary>
        /// Creates a instance.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static object CreateInstance(Type type)
        {
            return System.Activator.CreateInstance(type);
        }

    }
}
